﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Fiveesoft.Utility;
using NLUNZ.Admin;
using NLUNZ.Business;
using Telerik.Web.UI;

namespace NLUNZ.UserControls
{
    public partial class LatestAdsProperty : System.Web.UI.UserControl
    {
        private string _targetFolder;
        private string _targetFile = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            _targetFolder = Server.MapPath("~/Images/Ads/");
            showMessage.Text = string.Empty;
        }
        protected void Page_PreRender(object sender, EventArgs e)
        {
            HtmlMeta metatag = new HtmlMeta();
            metatag.Attributes.Add("http-equiv", "X-UA-Compatible");
            metatag.Attributes.Add("content", "IE=8;IE=7;IE=5");
            Page.Header.Controls.AddAt(0, metatag);
        }

        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            string url = Request.Url.ToString();
            Page.Response.Redirect(url);
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string imgUrl = string.Empty;
            if (RadUpload1.UploadedFiles.Count > 0)
            {
                foreach (UploadedFile file in RadUpload1.UploadedFiles)
                {
                    imgUrl = _targetFile == string.Empty ? file.GetName() : _targetFile;

                    string filePath = _targetFolder + imgUrl;

                    Size size = ImageHelper.GetDimensions(filePath);
                    StringBuilder message = new StringBuilder();

                        string name = txtImageName.Text;

                        Repository.InsertBanner(name, imgUrl);
                        resetUploadForm();
                        showMessage.Text = "<div class=\"success\">The file uploaded successfully.</div>";

                }
            }
        }

        private void resetUploadForm()
        {
            txtImageName.Text = string.Empty;
        }

        private void DeleteUploadedImage(string filename)
        {
            string filePath = _targetFolder + filename;
            FileInfo info = new FileInfo(filePath);
            info.Delete();
        }

    }
}